﻿using Max.PH4_2102A.Shopping.Domain;
using Max.PH4_2102A.Shopping.DTO;
using Max.PH4_2102A.Shopping.IService;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;

namespace Max.PH4_2102A.Shopping.API.Controllers
{
    /// <summary>
    /// 品牌控制器
    /// </summary>
    [Route("brand")]
    [ApiController]
    public class BrandController : ControllerBase
    {
        IBrandService _service;
        /// <summary>
        /// 构造函数注入
        /// </summary>
        /// <param name="service"></param>
        public BrandController(IBrandService service)
        {
            _service = service;
        }

        /// <summary>
        /// 添加品牌
        /// </summary>
        /// <param name="model"></param>
        /// <returns></returns>
        [HttpPost]
        public IActionResult Insert(BrandModel model)
        {
            ResponseResultDto result = new();

            int data = _service.Insert(model);

            if (data <= 0)
            {
                result.Code = ResponseStateCode.Failed;
                result.Message = "品牌名称已存在";
            }

            return Ok(result);
        }

    }
}
